package com.teach.service.impl.photo;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.commons.Id;
import com.teach.dto.NewsSearch;
import com.teach.entity.News;
import com.teach.mapper.NewsMapper;
import com.teach.service.photo.PhotoArticleService;

@Service
public class PhotoArticleServiceImpl implements PhotoArticleService{
	
	/**
	 * 添加文章实现
	 * suzuka
	 */
	
	@Autowired
	private NewsMapper mapper;
	
	@Autowired
	private Id id;
	
	@Override
	public void add(News news) {
		// TODO Auto-generated method stub
		news.setNewsId(id.nextId());
		news.setNewsTime(new Date());
		mapper.insert(news);
	}

	@Override
	public void update(News news) {
		// TODO Auto-generated method stub
		mapper.updateByPrimaryKeySelective(news);
	}

	@Override
	public void delete(Long newsId) {
		// TODO Auto-generated method stub
		mapper.deleteByPrimaryKey(newsId);
	}

	@Override
	public News get(Long newsId) {
		// TODO Auto-generated method stub
		return mapper.selectByPrimaryKey(newsId);
	}

	@Override
	public List<News> list(int startIndex, int len) {
		// TODO Auto-generated method stub
		PageInfo<News> pageInfo = PageHelper.offsetPage(startIndex, len).setCount(false).doSelectPageInfo(()->mapper.select(null));
		return pageInfo.getList();
	}

	@Override
	public PageInfo<News> page(int current, int rowMax) {
		// TODO Auto-generated method stub
		return PageHelper.startPage(current, rowMax).doSelectPageInfo(()->mapper.select(null));
	}

	@Override
	public PageInfo<News> pageSearch(NewsSearch search) {
		// TODO Auto-generated method stub
		return PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->mapper.select(search));
	}

}
